-- 更代
local gengdai = fk.CreateSkill {
    name = "mcdh_gengdai",
}

local U = require "packages/utility/utility"
local lib = require "packages/mcdh/lib"

gengdai:addEffect(fk.EventPhaseEnd,{
    can_trigger = function(self, event, target, player, data)
        return player:hasSkill(self) and target ~= player and target.phase == Player.Start and not player.chained
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        player:setChainState(true)
        local result, dat = room:askForUseActiveSkill(target, "#mcdh_gengdai_ac", "#mcdh_gengdai_discard:"..player.id, true)
        if result then
            room:throwCard(dat.cards, self.name, target)
        else
            local mark = target:getTableMark("#mcdh_gengdai_use")
            for _, p in ipairs(room.alive_players) do
                if p ~= player then
                    table.insertIfNeed(mark,p.id)
                end
            end
            room:setPlayerMark(target,"#mcdh_gengdai_use-turn",mark)
        end
    end
})

gengdai:addEffect('prohibit',{
    is_prohibited = function(self, from, to, card)
        local mark = from:getTableMark("#mcdh_gengdai_use-turn")
        return table.contains(mark,to.id)
    end,
})

Fk:loadTranslationTable {
    ["mcdh_gengdai"] = "更代",
    [":mcdh_gengdai"] = "其他角色准备阶段，你可以横置，令其选择一项：\n1. 本回合不能对除你以外的角色使用牌；\n2. 弃置两张类型不同的牌。",
    ["#mcdh_gengdai_discard"] = "更代：弃置两张类型不同的牌，否则本回合不能对除 %src 以外的角色使用牌",
}

return gengdai